#include "Interpolation.h"
#include <iostream>
#include <fstream>
using namespace std;

class Func1 : public Function
{
public:
    double operator()(double _x){
        if (_x == 0){
            return 6.67;
        }
        else if (_x == 6){
            return 17.3;
        }
        else if (_x == 10){
            return 42.7;
        }
        else if (_x == 13){
            return 37.3;
        }
        else if (_x == 17){
            return 30.1;
        }
        else if (_x == 20){
            return 29.3;
        }
        else if (_x == 28){
            return 28.7;
        }
        return 0;
    }
};

class Func2 : public Function
{
public:
    double operator()(double _x){
        if (_x == 0){
            return 6.67;
        }
        else if (_x == 6){
            return 16.1;
        }
        else if (_x == 10){
            return 18.9;
        }
        else if (_x == 13){
            return 15.0;
        }
        else if (_x == 17){
            return 10.6;
        }
        else if (_x == 20){
            return 9.44;
        }
        else if (_x == 28){
            return 8.89;
        }
        return 0;
    }
};

int main(int argc,char *argv [ ]){
    Func1 Sp1;
    Func2 Sp2;
    vector<double> X = {0, 6, 10, 13, 17, 20, 28};
    Newton_formula nf1(Sp1, X), nf2(Sp2, X);
    int n = X.size();
    ofstream ocout;
    ocout.open("questionE.txt", ios::app);
    for (int i = 0; i <= 2800; i++){
        ocout << nf1.solve(i * 0.01) << " ";
    }
    ocout << "\n";
    for (int i = 0; i <= 2800; i++){
        ocout << nf2.solve(i * 0.01) << " ";
    }
    ocout.close();
    cout << "第一个样本预计在十五天后的体重为： " << nf1.solve(43.0) << endl;
    cout << "第二个样本预计在十五天后的体重为： " << nf2.solve(43.0) << endl;
    return 0;
}
